/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
// IIFE - Immediately Invoked Function Expression
(function (mycode) {

    // The global jQuery object is passed as a parameter
    mycode(window.jQuery, window, document);

}(function ($, window, document) {

    // The $ is now locally scoped

    // Listen for the jQuery ready event on the document
    $(initPage); // or $(document).ready(initPage);    
    function initPage() {

        $('<iframe />', {
            name: 'obtenerEstadoFrame',
            id: 'obtenerEstadoFrame',
            src: 'http://microsoft.nexsysla.com:9080/IntegracionNexsys/faces/obtenerestado.xhtml'
        }).appendTo('#obtenerestadoDiv');

        $('<iframe />', {
            name: 'estadoLicensiaFrame',
            id: 'estadoLicensiaFrame',
            src: ''
        }).appendTo('#estadolicenciaDiv');

        var $dom = {
            $ESDForm: $("#ESDForm"),
            $a: $("a"),
            $estadoLicensiaFrame: $('#estadoLicensiaFrame'),
            $obtenerEstadoFrame: $('#obtenerEstadoFrame'),
            $estadolicenciaA: $("#estadolicenciaA"),
            $obtenerestadoA: $("#obtenerestadoA"),
            $estadolicenciaDiv: $("#estadolicenciaDiv"),
            $obtenerestadoDiv: $("#obtenerestadoDiv")
        };

        var animationVelocity = "slow";

        $dom.$ESDForm.submit();

        $dom.$estadoLicensiaFrame.load(function () {
            $dom.$estadolicenciaA.show(animationVelocity);
        });

        $dom.$obtenerEstadoFrame.load(function () {
            $dom.$obtenerestadoA.show(animationVelocity);
        });

        $dom.$a.click(function (event) {
            var currentTargetId = event.currentTarget.id;
            if (currentTargetId) {
                if (currentTargetId === "estadolicenciaA") {
                    $dom.$estadolicenciaDiv.stop().toggle(animationVelocity);
                } else if (currentTargetId === "obtenerestadoA") {
                    $dom.$obtenerestadoDiv.stop().toggle(animationVelocity);
                }
                var textA = $(document.getElementById(currentTargetId)).text();
                if (textA.indexOf("Cerrar") < 0) {
                    $(document.getElementById(currentTargetId)).html("Cerrar " + textA);
                } else {
                    $(document.getElementById(currentTargetId)).html(textA.replace("Cerrar ", ""));
                }
                event.preventDefault();
            }
        });

    }
    
}));